%--------------------------------------------------------------------------
% computes the time at which the path crosses the neutral stability curve
%--------------------------------------------------------------------------

function [t_c, k_c, M_c] = lo_comp_time(k_0, figs)

addpath ../
p = params;

M_0 = p.Ma_prime;

[k, M, neut] = lo_neutral_stab_curves(linspace(0, 3, 100), 0);

path = @(k) (k / k_0 - 1 + p.beta) / p.beta * M_0;

opts = optimset('tolFun',1e-14,'tolX',1e-10);
k_c = fsolve(@(k) path(k) - neut(k), k_0, opts);
h_c = k_c / k_0;
M_c = path(k_c);

tau_c = 1 - h_c - (1 - p.beta) * log((h_c - (1 - p.beta)) / p.beta);
t_c = tau_c / p.delta;


if figs
    plot(k, M, k, path(k));
    hold on;
    plot(k_c, M_c, 'k*');
    plot(k_c, neut(k_c), 'ro');
    ylim([0, max(M)]);
end